| 1 | package net.mandaria.tippytipper.activities; |
| 2 | |
| 3 | import java.util.HashMap; |
| 4 | import java.util.Map; |
| 5 | |
| 6 | import com.flurry.android.FlurryAgent; |
| 7 | |
| 8 | import net.mandaria.tippytipper.R; |
| 9 | import net.mandaria.tippytipper.TippyTipperApplication; |
| 10 | import android.app.Activity; |
| 11 | import android.content.Intent; |
| 12 | |
| 13 | import android.os.Bundle; |
| 14 | |
| 15 | |
| 16 | import android.view.*; |
| 17 | import android.view.View.OnClickListener; |
| 18 | |
| 19 | import android.widget.*; |
| 20 | |
| 21 | public class SplitBill extends Activity { |
| 22 | |
| 23 | |
| 24 | /** Called when the activity is first created. */ |
| 25 | @Override |
| 26 | public void onCreate(Bundle savedInstanceState) { |
| 27 | super.onCreate(savedInstanceState); |
| 28 | setContentView(R.layout.splitbill); |
| 29 | |
| 30 | TippyTipperApplication appState = ((TippyTipperApplication)this.getApplication()); |
| 31 | |
| 32 | splitBill(appState.service.getNumberOfPeople()); |
| 33 | |
| 34 | View btn_add_person = findViewById(R.id.btn_add_person); |
| 35 | btn_add_person.setOnClickListener(new OnClickListener() |
| 36 | { |
| 37 | public void onClick(View v) |
| 38 | { |
| 39 | addPerson(); |
| 40 | FlurryAgent.onEvent("Add Person Button"); |
| 41 | } |
| 42 | }); |
| 43 | |
| 44 | View btn_remove_person = findViewById(R.id.btn_remove_person); |
| 45 | btn_remove_person.setOnClickListener(new OnClickListener() |
| 46 | { |
| 47 | public void onClick(View v) |
| 48 | { |
| 49 | removePerson(); |
| 50 | FlurryAgent.onEvent("Remove Person Button"); |
| 51 | } |
| 52 | }); |
| 53 | |
| 54 | } |
| 55 | |
| 56 | @Override |
| 57 | public void onStart() |
| 58 | { |
| 59 | super.onStart(); |
| 60 | boolean enableErrorLogging = Settings.getEnableErrorLogging(getBaseContext()); |
| 61 | String API = getString(R.string.flurrykey); |
| 62 | if(!API.equals("") && enableErrorLogging == true) |
| 63 | { |
| 64 | FlurryAgent.setContinueSessionMillis(30000); |
| 65 | FlurryAgent.onStartSession(this, API); |
| 66 | } |
| 67 | } |
| 68 | |
| 69 | @Override |
| 70 | public void onStop() |
| 71 | { |
| 72 | super.onStop(); |
| 73 | FlurryAgent.onEndSession(this); |
| 74 | } |
| 75 | |
| 76 | @Override |
| 77 | public boolean onCreateOptionsMenu(Menu menu) |
| 78 | { |
| 79 | super.onCreateOptionsMenu(menu); |
| 80 | |
| 81 | //MenuInflater inflater = getMenuInflater(); |
| 82 | //inflater.inflate(R.menu.menu, menu); |
| 83 | FlurryAgent.onEvent("Disabled Menu Button"); |
| 84 | return true; |
| 85 | } |
| 86 | |
| 87 | @Override |
| 88 | public boolean onOptionsItemSelected(MenuItem item) |
| 89 | { |
| 90 | switch(item.getItemId()) |
| 91 | { |
| 92 | case R.id.settings: |
| 93 | startActivity(new Intent(this, Settings.class)); |
| 94 | FlurryAgent.onEvent("Settings Button"); |
| 95 | return true; |
| 96 | } |
| 97 | return false; |
| 98 | } |
| 99 | |
| 100 | private void addPerson() |
| 101 | { |
| 102 | TippyTipperApplication appState = ((TippyTipperApplication)this.getApplication()); |
| 103 | int people = appState.service.getNumberOfPeople() + 1; |
| 104 | |
| 105 | splitBill(people); |
| 106 | |
| 107 | |
| 108 | } |
| 109 | |
| 110 | private void removePerson() |
| 111 | { |
| 112 | TippyTipperApplication appState = ((TippyTipperApplication)this.getApplication()); |
| 113 | int people = appState.service.getNumberOfPeople() - 1; |
| 114 | |
| 115 | if(people > 1) |
| 116 | splitBill(people); |
| 117 | } |
| 118 | |
| 119 | private void splitBill(int people) |
| 120 | { |
| 121 | TippyTipperApplication appState = ((TippyTipperApplication)this.getApplication()); |
| 122 | appState.service.splitBill(people); |
| 123 | |
| 124 | bindData(); |
| 125 | } |
| 126 | |
| 127 | private void bindData() |
| 128 | { |
| 129 | TippyTipperApplication appState = ((TippyTipperApplication)this.getApplication()); |
| 130 | |
| 131 | TextView lbl_split_amount = (TextView)findViewById(R.id.lbl_split_amount); |
| 132 | TextView lbl_split_tip = (TextView)findViewById(R.id.lbl_split_tip); |
| 133 | TextView lbl_split_adjustment = (TextView)findViewById(R.id.lbl_split_adjustment); |
| 134 | TextView lbl_split_total = (TextView)findViewById(R.id.lbl_split_total); |
| 135 | TextView lbl_NumberOfPeople = (TextView)findViewById(R.id.lbl_NumberOfPeople); |
| 136 | |
| 137 | View inflated_splitTax = findViewById(R.id.inflated_splitTax); |
| 138 | |
| 139 | float excludeTaxRate = Settings.getExcludeTaxRate(getBaseContext()); |
| 140 | if(excludeTaxRate != 0) |
| 141 | { |
| 142 | ViewStub stub_splitTax = (ViewStub)findViewById(R.id.stub_splitTax); |
| 143 | if(stub_splitTax != null) |
| 144 | stub_splitTax.setVisibility(View.VISIBLE); |
| 145 | else if(inflated_splitTax != null) |
| 146 | inflated_splitTax.setVisibility(View.VISIBLE); |
| 147 | TextView lbl_split_tax = (TextView)findViewById(R.id.lbl_split_tax); |
| 148 | lbl_split_tax.setText(appState.service.getSplitTaxAmount()); |
| 149 | } |
| 150 | else |
| 151 | { |
| 152 | if(inflated_splitTax != null) |
| 153 | inflated_splitTax.setVisibility(View.GONE); |
| 154 | } |
| 155 | |
| 156 | lbl_split_amount.setText(appState.service.getSplitBillAmount()); |
| 157 | lbl_split_tip.setText(appState.service.getSplitTipAmount()); |
| 158 | lbl_split_adjustment.setText(appState.service.getSplitAdjustment()); |
| 159 | lbl_split_total.setText(appState.service.getSplitTotalAmount()); |
| 160 | lbl_NumberOfPeople.setText(Integer.toString(appState.service.getNumberOfPeople())); |
| 161 | |
| 162 | Map<String, String> params = new HashMap<String, String>(); |
| 163 | params.put("Number of People", String.valueOf(appState.service.getNumberOfPeople())); |
| 164 | params.put("Split Bill Amount", appState.service.getSplitBillAmount()); |
| 165 | params.put("Split Tax Amount", appState.service.getSplitTaxAmount()); |
| 166 | params.put("Split Tip Amount", appState.service.getSplitTipAmount()); |
| 167 | params.put("Split Adjustment Amount", appState.service.getSplitAdjustment()); |
| 168 | params.put("Split Total Amount", appState.service.getSplitTotalAmount()); |
| 169 | FlurryAgent.onEvent("Split Bill Bind Data", params); |
| 170 | |
| 171 | } |
| 172 | } |